package com.usian.controller;

import com.alibaba.fastjson.JSON;
import com.usian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/test")
public class Producer {


    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @RequestMapping("/send")
    public String send(){

        User user =new User();
        user.setUserName("张三");
        user.setAge(18);

        List<String> addrList =new ArrayList<>();
        addrList.add("海淀上庄");
        addrList.add("延庆是多少");
        addrList.add("顺义333333");

        user.setData(addrList);
        kafkaTemplate.send("topic", JSON.toJSONString(user));
        return "1111";
    }
}
